package com.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.web.entity.SysNav;
import com.web.service.SysNavService;

@Controller
@RequestMapping("nav")
public class SysNavController {

	@Autowired
	private SysNavService sysNavService;

	@ResponseBody
	@RequestMapping("sysNav")
	public List<SysNav> sysNav() {
		return sysNavService.queryAllsysNav();
	}

	@RequestMapping("adminNav")
	public String adminNav(Model model) {
		model.addAttribute("Navlist", sysNavService.getAllNav());
		return "manage/adminNav";
	}

	@ResponseBody
	@RequestMapping("addNav")
	public void addNav(@RequestParam("title") String title, @RequestParam("icon") String icon,
			@RequestParam("state") Integer state) {
		sysNavService.addNav(title, icon, state);
	}

	@ResponseBody
	@RequestMapping("updateState")
	public Map<String, Object> updateState(@RequestParam("id") Integer id, @RequestParam("state") Integer state) {
		Map<String, Object> map = new HashMap<String, Object>();
		if (state == 1) {
			state = 0;
		} else {
			state = 1;
		}
		// System.out.println(id+" #### "+state);
		map = sysNavService.changeNavState(id, state);
		return map;
	}

	@ResponseBody
	@RequestMapping("detNav")
	public Map<String, Object> delRow(@RequestParam("id") Integer id) {
		Map<String, Object> map = new HashMap<String, Object>();
		map = sysNavService.delRowNav(id);
		return map;
	}

}
